package com.baihan.angus.app.game.busshow.pop_dialog;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.baihan.angus.app.game.busshow.R;
import com.baihan.angus.app.game.busshow.adps.ScriptDialogTitleAdp;

import java.util.List;

public class ManualPopup extends PopupWindow {
    private Context mContext;
    private RecyclerView rvMenu;

    private OnSelectListener mOnSelectListener;
    private ScriptDialogTitleAdp mScriptDialogTitleAdp;

    public ManualPopup(Context context, List<String> titleList, int selectPosition, OnSelectListener onSelectListener) {
        super(context);
        this.mContext = context;
        mOnSelectListener = onSelectListener;
        View contentView = LayoutInflater.from(context).inflate(R.layout.manual_popup, null);
        setContentView(contentView);
        setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setOutsideTouchable(true);
        // 设置PopupWindow是否能响应点击事件
        setTouchable(true);
        setFocusable(true);

        rvMenu = contentView.findViewById(R.id.rvMenu);

        mScriptDialogTitleAdp = new ScriptDialogTitleAdp();
        rvMenu.setLayoutManager(new LinearLayoutManager(mContext, RecyclerView.VERTICAL, false));
        mScriptDialogTitleAdp.bindToRecycleView(rvMenu);

        mScriptDialogTitleAdp.clear();
        mScriptDialogTitleAdp.addAll(titleList);
        mScriptDialogTitleAdp.setThisPosition(selectPosition);
        mScriptDialogTitleAdp.notifyDataSetChanged();

        mScriptDialogTitleAdp.setOnItemClickListener(new ScriptDialogTitleAdp.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                if (mOnSelectListener != null) {
                    mOnSelectListener.onSelect(position);
                }
            }
        });
    }

    public interface OnSelectListener {
        void onSelect(int position);
    }
}
